package com.adtech.farmProducts.adapter;

import android.view.View;
import android.widget.TextView;

import com.adtech.common.widgets.recycler.RecyclerViewAdapter;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.base.BillingTypeInfo;


/**
 * Author:  xiaocz.
 * Date:    2018/05.04.
 * Descr:  我的计费模板
 */
public class BillingInfoAdapter extends RecyclerViewAdapter<BillingTypeInfo> {

    private static onClickListener onClickListener;
    public BillingInfoAdapter(AdapterListener<BillingTypeInfo> adapterListener) {
        super(adapterListener);
    }

    public void setBillingInfoOnClickListener(onClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    @Override
    protected int getItemViewType(int position, BillingTypeInfo data) {
        return R.layout.item_billing;
    }

    @Override
    protected ViewHolder<BillingTypeInfo> getViewHolder(View view, int viewType) {
        return new InfoTypeViewHolder(view);
    }

    private static class InfoTypeViewHolder extends ViewHolder<BillingTypeInfo> {

        private TextView tvTime,tv_qblc,tv_qbj,tv_clcj;

        public InfoTypeViewHolder(View itemView) {
            super(itemView);
            tvTime = itemView.findViewById(R.id.tv_time);
            tv_qblc=itemView.findViewById(R.id.tv_qblc);
            tv_qbj=itemView.findViewById(R.id.tv_qbj);
            tv_clcj=itemView.findViewById(R.id.tv_clcj);
        }

        @Override
        protected void onBind(final BillingTypeInfo data, final int position) {
            tvTime.setText(String.format("[%s-%s]",data.getQishitime(),data.getJieshutime()));
            tv_qblc.setText(String.format("%s公里",data.getQibukm()));
            tv_qbj.setText(String.format("%s元",data.getQibuprice()));
            tv_clcj.setText(String.format("%s公里/%s元",data.getChaochukm(),data.getChaochuprice()));
            tv_qbj.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClickButton(0,position,data);
                }
            });
            tv_qblc.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClickButton(1,position,data);
                }
            });
            tv_clcj.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClickButton(2,position,data);
                }
            });
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }
    public interface onClickListener {
        void onClickButton(int value, int position, BillingTypeInfo data);
    }
}